package com.wantupai.mvp.framework.support.viewstate.activity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.wantupai.mvp.framework.support.activity.ActivityMvpDelegateImpl;
import com.wantupai.mvp.framework.support.viewstate.MvpViewStateDelegateCallback;
import com.wantupai.mvp.framework.support.viewstate.ViewState;
import com.wantupai.mvp.mvp.MvpPresenter;
import com.wantupai.mvp.mvp.MvpView;
import com.wantupai.mvp.mvp.lce.activity.MvpActivity;


/**
 * 代理对象
 * 备忘录模式-->创建备忘录角色
 *
 * @param <V>
 * @param <P>
 * @author :zhangqing
 */
public abstract class MvpViewStateActivity<D, V extends MvpView<D>, P extends MvpPresenter<V>, VS extends ViewState<V>> extends MvpActivity<D, V, P> implements MvpViewStateDelegateCallback<V, P, VS>
{

    private VS viewState;
    //是否已经恢复状态
    protected boolean restoringViewState;

    @Override
    public ActivityMvpDelegateImpl<V, P> getMvpDelegate()
    {
        if (mvpDelegate == null)
        {
            mvpDelegate = new ActivityMvpViewStateDelegateImpl<>(this, this, true);
        }
        return super.getMvpDelegate();
    }

    @Override
    protected void onPostCreate(@Nullable Bundle savedInstanceState)
    {
        super.onPostCreate(savedInstanceState);
        getMvpDelegate().onPostCreate(savedInstanceState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState)
    {
        super.onSaveInstanceState(outState);
        getMvpDelegate().onSaveInstanceState(outState);
    }

    @Override
    public VS getViewState()
    {
        return viewState;
    }

    @Override
    public void setViewState(VS viewState)
    {
        this.viewState = viewState;
    }

    @NonNull
    @Override
    public VS createViewState()
    {
        return viewState;
    }

    @Override
    public void setRestoringViewState(boolean restoringViewState)
    {
        this.restoringViewState = restoringViewState;
    }

    @Override
    public void onViewStateInstanceRestored(boolean instanceStateRetained)
    {

    }

}
